<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
<script src="__JS__/clipboard.min.js"></script>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-form-item layui-inline">
							<select name="year">
								<option value="">选择年份</option>
								{for start="$old_year" end="date('Y')+1"}
									{if $year == $i}
									<option value="{$i}" selected="selected">{$i}年</option>
									{else/}
									<option value="{$i}">{$i}年</option>
									{/if}
								{/for}
							</select>
						</div>
						
						<div class="layui-form-item layui-inline">
							<select name="month">
								<option value="">选择月份</option>
								{for start="1" end="13"}
									{if $month == $i}
									<option value="{$i}" selected="selected">{$i}月</option>
									{else/}
									<option value="{$i}">{$i}月</option>
									{/if}
								{/for}
							</select>
						</div>
						
						<div class="layui-form-item layui-inline">
							<select name="day">
								<option value="">选择天数</option>
								{for start="1" end="32"}
									{if $month == $i}
									<option value="{$i}" selected="selected">{$i}日</option>
									{else/}
									<option value="{$i}">{$i}日</option>
									{/if}
								{/for}
							</select>
						</div>
						
						<div class="layui-form-item layui-inline">
							<input name="status" type="radio" value="" title="所有" {if $status==''} checked {/if}>
							<input name="status" type="radio" value="0" title="草稿" {if $status===0} checked {/if}>
							<input name="status" type="radio" value="1" title="已付" {if $status==1} checked {/if}>
							<input name="status" type="radio" value="2" title="退款" {if $status==2} checked {/if}>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-form-item layui-inline">
						   <div class="layui-input-inline2 input-group">
							   <span class="input-group-addon">订单号</span>
							   <input type="text" name="number" placeholder="" class="layui-input">
						   </div>
						</div>
						
						<div class="layui-form-item layui-inline">
						   <div class="layui-input-inline2 input-group">
							   <span class="input-group-addon">客户</span>
							   <input type="text" name="keyword" placeholder="昵称 / 公司名称" class="layui-input">
						   </div>
						</div>
						
                       <div class="layui-form-item layui-inline">
						   <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
							   <i class="layui-icon layui-icon-search"></i>
							   查询
						   </button>
						   <button type="reset" class="pear-btn pear-btn-md">
							   <i class="layui-icon layui-icon-refresh"></i>
							   重置
						   </button>
                       </div>
                    </div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="dataTable" lay-filter="dataTable"></table>
			</div>
		</div>

		<script type="text/html" id="numberbox">
		<div>
			<a href="javascript:;" popDealInfo="{:U('deal.main/info')}/id/{{d.id}}/number/{{d.number}}" title="{{d.number}} 订单详情">{{d.number}}</a>
		</div>
		</script>

        <script type="text/html" id="customer">
		<div copy="{{d.customer.name}},{{d.customer.phone}},{{d.customer.address2}}">
			<a href="javascript:;" title="点击复制客户地址信息">{{ d.customer.name }}
			{{# if(d.customer.company!=""){ }} | {{ d.customer.company }} {{# } }}
			</a>
		</div>
		</script>
		
		<script type="text/html" id="count">
		<div>
			{{# if(d.volume>0){ }} {{ d.volume }} 匹 {{# }else{ }} {{ d.count }} 米 {{# } }}
		</div>
		</script>
		
		<script type="text/html" id="status">
		<div>
			{{# if(d.status==1){ }}
			<span class="layui-tag pear-btn-green">已付</span>
			{{# }else if(d.status==2){ }}
			<span class="layui-tag pear-btn-red">退货</span>
			{{# }else{ }}
			<span class="layui-tag pear-btn-grey">草稿</span>
			{{# } }}
		</div>
		</script>
		
		<script type="text/html" id="paytype">
		<div>
			{{# if(d.cost==0){ }}
			<span style="color:#CFCFCF;">{{ d.paytype }}</span>
			{{# }else{ }}
			<span>{{ d.paytype }}</span>
			{{# } }}
		</div>
		</script>
		
		<script type="text/html" id="cost">
			<div><span style="color:#D32D27;">{{ d.cost }} 元</span></div>
		</script>

		<script type="text/html" id="toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
<!--            <button class="pear-btn pear-btn-md" lay-event="recycle">
		        <i class="layui-icon layui-icon-delete"></i>
		        回收站
		    </button> -->
			
			<button class="pear-btn pear-btn-primary pear-btn-md toolbar-btn-left" lay-event="pop" url="{:U('deal.main/history')}" poptitle="历史订单明细" popsize="0.98">
			    <i class="layui-icon layui-icon-search"></i>
			    历史订单明细
			</button>
			<button class="pear-btn pear-btn-ext1 pear-btn-md" lay-event="prints" poptitle="合并打印">
			    <i class="layui-icon layui-icon-print"></i>
			    合并打印
			</button>
			<button class="pear-btn pear-btn-ext2 pear-btn-md" lay-event="upcolor" poptitle="更新订单颜色">
			    <i class="layui-icon layui-icon-theme"></i>
			    更新订单颜色
			</button>
		</script>

		<script type="text/html" id="options">
		
		{if isMobile()}
		<div class="layui-row">
			<div class="layui-col-xs10">
			  {{ d.create_time }}
			</div>
			<div class="layui-col-xs2 layui-right">
			  {{# if(d.status==1){ }}
			  <span class="layui-tag pear-btn-green">已付</span>
			  {{# }else if(d.status==2){ }}
			  <span class="layui-tag pear-btn-red">退货</span>
			  {{# }else{ }}
			  <span class="layui-tag pear-btn-grey">草稿</span>
			  {{# } }}
			</div>
		</div>
		<div class="layui-row">
			<div class="layui-col-xs12">
				{{ d.customer.name }}
				{{# if(d.customer.company!=""){ }} | {{ d.customer.company }} {{# } }}
			</div>
		</div>
		<div class="layui-row">
			<div class="layui-col-xs4">
				{{ d.paytype }}
			</div>
			<div class="layui-col-xs4">
				数量：{{# if(d.volume>0){ }} {{ d.volume }} 匹 {{# }else{ }} {{ d.count }} 米 {{# } }}
			</div>
			<div class="layui-col-xs4 layui-right">
				数量：{{ d.total }}元
			</div>
		</div>
		{/if}
		
		<div class="layui-options">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" {if isMobile()} popsize="1" {/if}><i class="layui-icon layui-icon-edit"></i></button>
			<button class="pear-btn pear-btn-cyan pear-btn-sm" lay-event="pop" url="{:U('deal.main/history')}/cusid/{{ d.cusid }}" poptitle="【{{ d.customer.name }}】历史订单" popsize="0.98"><i class="layui-icon layui-icon-search"></i></button>
			<button class="pear-btn pear-btn-primary pear-btn-sm" {if isMobile()} lay-event="link" {else/} lay-event="pop" {/if} url="{:U('deal.main/printing')}/id/{{d.id}}/number/{{d.number}}" poptitle="【{{ d.customer.name }}】订单明细"><i class="layui-icon layui-icon-print"></i></button>
			{{# if(d.volume>0){ }}
			<button class="pear-btn pear-btn-yellow pear-btn-sm" lay-event="pop" url="{:U('deal.main/label')}/id/{{d.id}}/number/{{d.number}}" poptitle="【{{ d.customer.name }}】大货标签"><i class="layui-icon layui-icon-note"></i></button>
			{{# } }}
			<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</div>
		
		</script>
        <script>
        layui.use(['jquery','common','mycomm','table'], function() {
            let $ = layui.jquery;
			let common = layui.common;
			let mycomm = layui.mycomm;
			let table = layui.table;
			let $table_name = "dataTable";
            let MODULE_PATH = "{$MODULE_PATH}";
            
			{if isMobile()}
				let cols = [
				    [
						{
							title: '操作',
							toolbar: '#options',
							unresize: true,
							align: 'left',
				        }
				    ]
				];
			{else}
				let cols = [
				    [{
						  type: 'checkbox',
						}, {
						   field: "id",
						   title: "ID",
						   width: 80,
						   unresize: "true",
						   hide:"true",
						   align: "center"
						}, {
						   field: "create_time2",
						   title: "下单时间",
						   width: 120,
						   unresize: "true",
						   align: "center",
						   sort:true,
						}, {
						   field: "number",
						   title: "订单号",
						   width: 170,
						   templet : "#numberbox",
						   unresize: "true",
						   align: "center"
						}, {
						   field: "cus_name",
						   title: "客户昵称",
						   width: 300,
						   unresize: "true",
						   templet: "#customer",
						   align: "left"
						}, {
						   field: "count",
						   title: "数量",
						   width: 100,
						   templet: "#count",
						   unresize: "true",
						   align: "center",
						}, {
							field: "total",
							title: "总金额",
							width: 120,
							templet: "<div>{{d.total}} 元</div>",
							unresize: "true",
							align: "center"
						}, {
						{if $cost==1}
							field: "cost",
							title: "成本",
							width: 120,
							templet: "#cost",
							unresize: "true",
							align: "center"
						}, {
						{/if}
						   field: "paytype",
						   title: "支付方式",
						   templet: "#paytype",
						   width: 120,
						   unresize: "true",
						   align: "center"
						}, {
						   field: "courier",
						   title: "快递名称",
						   width: 120,
						   unresize: "true",
						   align: "center",
						}, {
						   field: "remark",
						   title: "备注",
						   width: 160,
						   unresize: "true",
						   align: "center"
						}, {
						   field: "status",
						   title: "状态",
						   width: 100,
						   templet: "#status",
						   unresize: "true",
						   align: "center"
						}, {
							title: '操作',
							toolbar: '#options',
							width: 250,
							fixed: "right",
							unresize: true,
							align: 'left',
				        }
				    ]
				];
			{/if}
            
			
			table.render({
				elem: '#dataTable',
				url: MODULE_PATH + 'index',
				where:{
					{if $year!=''}year:{$year},{/if}
					{if $month!=''}month:{$month},{/if}
					{if $day!=''}day:{$day},{/if}
					{if $cusid!=''}cusid:{$cusid},{/if}
					{if $status!=''}status:{$status},{/if}
				},
				page: true,
				cols: cols,
				cellMinWidth: 100,
				even: true,
				limit: 30,
				toolbar: '#toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports'],
				done: function(res, curr, count){
					// $('#total').html(res.total);
					// $('#count').html(res.count);
				}
			});
			
			mycomm.tableTool('{$controller_title}',MODULE_PATH,$table_name);
			mycomm.search_table($table_name);
			mycomm.tableSetVal(MODULE_PATH);
			mycomm.formSwitch('status',MODULE_PATH);
			
			mycomm.tableToolBar('{$controller_title}',MODULE_PATH,$table_name,function(obj){
				if(obj.event === "prints"){
					let data = table.checkStatus(obj.config.id).data;
					if (data.length === 0) {
						Alert('未选中数据');
					    return false;
					}
					var ids = []
					var hasCheck = table.checkStatus($table_name)
					var hasCheckData = hasCheck.data
					if (hasCheckData.length > 0) {
					    $.each(hasCheckData, function (index, element) {
					        ids.push(element.id)
					    })
					}
					ids=ids.join('|');
					var url = MODULE_PATH + "printing?mid=" + ids;
					mycomm.tool_pop(url,"合并订单明细");
				}else if(obj.event === "upcolor"){
					var url = MODULE_PATH + "updealcolor";
					mycomm.ajax(url,{},"GET",function(res){
						Alert(res.msg,'success');
					},{},function(){
						
					});
				}
			});
			
			$('body').on('click', '[popDealInfo]',function(){
			    var title=$(this).attr('title');
				var url=$(this).attr('popDealInfo');
				mycomm.tool_pop(url,title,0.9);
			})
        })
    </script>
	{$LOAD_STYLE.bottom|raw}
	</body>
</html>
